package cloud.xlh.infrastructure.enums;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 *
 * @ project name : xlh_osms
 * @ Author: XuLeHuang
 * @ Date: 2023/10/1 11:15
 * @ Description:
 */
public enum CacheComponentEnum {
    REDIS(0, "redis"),
    CAFFEINE(1, "caffeine"),
    ORDER_REDIS(2, "orderRedis");

    private static final Set<Integer> enumSet = new HashSet<>(10);

    static {
        Arrays.asList(CacheComponentEnum.values()).forEach(e -> enumSet.add(e.getCode()));
    }

    public static boolean hasEnum(Integer code) {
        return enumSet.contains(code);
    }


    private Integer code;

    private String beanName;

    CacheComponentEnum(Integer code, String beanName) {
        this.code = code;
        this.beanName = beanName;
    }

    public Integer getCode() {
        return code;
    }

    public String getBeanName() {
        return beanName;
    }

    public static String getDesc(Integer code) {
        CacheComponentEnum[] values = values();
        if (code == null)
            return null;
        for (CacheComponentEnum value : values) {
            if (value.code.equals(code)) {
                return value.beanName;
            }
        }
        return null;
    }
}
